package com.dongdongshop.service;

import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.pojo.TbTypeTemplateExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbTypeTemplateServiceImpl implements TbTypeTemplateService {

    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    @Override
    public Page<TbTypeTemplate> selectList(TbTypeTemplate tbTypeTemplate, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbTypeTemplate> tbTypeTemplates = tbTypeTemplateMapper.selectByName(tbTypeTemplate);
        PageInfo info = new PageInfo(tbTypeTemplates);

        return new Page(info.getPageNum(),info.getPageSize(),info.getPages(),info.getTotal(),info.getList());
    }

    @Override
    public boolean insertByT(TbTypeTemplate tbTypeTemplate) {
        int i = tbTypeTemplateMapper.insert(tbTypeTemplate);
        return i>0;
    }

    @Override
    public TbTypeTemplate selectById(Long id) {
        TbTypeTemplate tbTypeTemplate = tbTypeTemplateMapper.selectByPrimaryKey(id);
        return tbTypeTemplate;
    }

    @Override
    public boolean updateByT(TbTypeTemplate tbTypeTemplate) {
        int i = tbTypeTemplateMapper.updateByPrimaryKey(tbTypeTemplate);
        return i>0;
    }

    @Override
    public boolean deleteByIds(Integer[] ids) {
        int i = tbTypeTemplateMapper.deleteByIds(ids);
        return i>0;
    }

    @Override
    public TbTypeTemplate selectTid(Long typeId) {
        TbTypeTemplateExample te = new TbTypeTemplateExample();
        TbTypeTemplateExample.Criteria criteria = te.createCriteria();
        criteria.andIdEqualTo(typeId);
        List<TbTypeTemplate> tbTypeTemplates = tbTypeTemplateMapper.selectByExample(te);
        TbTypeTemplate tbTypeTemplate = tbTypeTemplates.size() > 0 ? tbTypeTemplates.get(0) : null;
        return tbTypeTemplate;

    }

}
